﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Windows;
using System.Reflection;
using System.IO;
using System.Text.RegularExpressions;

namespace IIFProcessor
{
    /// <summary>
    /// read data for ExpenseCategories
    /// </summary>
    internal static class ExpenseCategories
    {
        public const string dataLineStart = "ACCNT";
        public const string ExpenseCategoriesFile = "Chart-of-Accounts.IIF";

        public static List<string> GetCategories(string Categories)
        {
            List<string> lstCategories = new List<string>();
          
            try
            {
                string[] lines = Regex.Split(Categories, "\r\n");

                foreach (string line in lines)
                {
                    string[] splittedExpenseLine = line.Split('\t');
                    if (splittedExpenseLine[0] == dataLineStart)// && Settings.Default.AccountTypes.Contains(splittedExpenseLine[4]))
                    {
                        lstCategories.Add(splittedExpenseLine[1]);
                    }
                }

                //TextReader tReader = new StreamReader(Categories);
                //while (tReader.Peek() >= 0)
                //{
                //    string expensesLine = tReader.ReadLine();
                //    string[] splittedExpenseLine = expensesLine.Split('\t');
                //    if (splittedExpenseLine[0] == dataLineStart)// && Settings.Default.AccountTypes.Contains(splittedExpenseLine[4]))
                //    {
                //        lstCategories.Add(splittedExpenseLine[1]);
                //    }
                //}
                //tReader.Close();
                //lstCategories.Sort();
                return lstCategories;
            }
            catch
            {
                throw new Exception("Failed to load categories.");
            }

        }
    }
}
